package com.jiantu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jiantu.common.PageBean;
import com.jiantu.domain.dto.PageDTO;
import com.jiantu.domain.pojo.Classes;
import com.jiantu.mapper.ClassesMapper;
import com.jiantu.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesServiceImpl implements ClassesService {

    @Autowired
    private ClassesMapper classesMapper;

    @Override
    public Classes findById(Integer id){
        return classesMapper.findById(id);
    }

    @Override
    public PageBean findByPage(PageDTO pageDTO) {
        PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
        List<Classes> classesList = classesMapper.findByPage();
        Page p = (Page) classesList;
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public int insert(Classes classes){

       return classesMapper.insert(classes);
    }

    @Override
    public int update(Classes classes){

        return classesMapper.update(classes);
    }

    @Override
    public int deleteById(Integer id){
        return classesMapper.deleteById(id);
    }

}
